package com.kc.business.service.impl;

import com.kc.business.domain.BizOrderAddress;
import com.kc.business.domain.BizOss;
import com.kc.business.mapper.BizOrderAddressMapper;
import com.kc.business.service.IBizOrderAddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/10/13
 */
@Service
public class BizOrderAddressServiceImpl implements IBizOrderAddressService {
    @Resource
    BizOrderAddressMapper orderAddressMapper;

    /**
     * 查询地址列表
     *
     * @param orderAddress
     * @return
     */
    @Override
    public List<BizOrderAddress> getList(BizOrderAddress orderAddress) {
        return orderAddressMapper.select(orderAddress);
    }

    /**
     * 新增地址
     *
     * @param orderAddress
     * @return
     */
    @Override
    public int add(BizOrderAddress orderAddress) {
        return orderAddressMapper.insertSelective(orderAddress);
    }

    /**
     * 修改地址
     *
     * @param orderAddress
     * @return
     */
    @Override
    @Transactional
    public int edit(BizOrderAddress orderAddress) {
        if ("1".equals(orderAddress.getStatus())) {
            BizOrderAddress address = new BizOrderAddress();
            address.setStatus("0");
            Example example = new Example(BizOss.class);
            orderAddressMapper.updateByExampleSelective(address, example);
        }
        return orderAddressMapper.updateByPrimaryKeySelective(orderAddress);
    }

    /**
     * 删除地址
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return orderAddressMapper.deleteByPrimaryKey(id);
    }
}
